using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Dimok;
using Docs = Dimok.Documents;
using Dimok.Exceptions;
using Dimok.Images;
using Data;

namespace Dimok.Aspx.Manager.Forms {
	public partial class ContractTitle : Page_AL {
		protected void Page_Load(object sender, System.EventArgs e) {
			string formDir = Dimok.HttpEx.MapPath("/Data/Forms/Word/Contract_Title(Envelop).doc");
//			try{
				string msID = UOX.QueryParam.Get("MsID");
				if( msID == "" )return;
				DataSet ds = SQL.ExecuteDatasetEx(db,"SELECT XFA_CLASSACCOUNT MsID,XFA_VIN VIN,XFA_NAME Name FROM v_ExportFromMegasys WHERE XFA_CLASSACCOUNT=@MsID",msID);
				byte[] file = FileManager.GetBytesFromFile(new Docs.Word().FillForm(formDir,ds.Tables[0]),ds.Tables[0].Rows.Count > 0);
				Visible = false;
				Response.Cache.SetMaxAge(new TimeSpan(0,0,Config.Forms.MaxAge));
				Response.ContentType = Enums.GetContentType(file);
				//Response.AddHeader("content-disposition","attachment; filename=\"Envelop.doc\"");
				Response.BinaryWrite(file);
//			}catch(Exception exc){ throw new ClientException(formDir,exc,new NameValueCollectionEx("FormDir",formDir)); }
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e) {
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() {    
		}
		#endregion
	}
}
